﻿using System;

namespace Resolve
{
    public static class ResolveConfig
    {
        /// <summary>
        /// 需要编译文件后缀名
        /// </summary>
        public static string TemplateExe = "shtml";
        /// <summary>
        /// 动态编译命名空间
        /// </summary>
        public static string CompileNameSpace = "TempNameSpace";
        /// <summary>
        /// 应用程序目录
        /// </summary>
        public static readonly string AppPath = AppDomain.CurrentDomain.BaseDirectory;
        /// <summary>
        /// 动态编译DLL保存目录
        /// </summary>
        public static readonly string CompileSavePath = AppDomain.CurrentDomain.DynamicDirectory + "\\";
        /// <summary>
        /// 标志ASCII码 @
        /// </summary>
        public static int Flag = 64;
        /// <summary>
        /// 属性代码生成方法的名称
        /// </summary>
        public static string PropertyCodeName = "PropertyFunc";
        /// <summary>
        /// 方法代码生成方法的名称
        /// </summary>
        public static string FuncCodeName = "FuncFunc";
        /// <summary>
        /// 语句体代码生成方法的名称
        /// </summary>
        public static string BodyCodeName = "BodyFunc";
        /// <summary>
        /// 内容符生成方法的名称
        /// </summary>
        public static string PlaceContentName = "ContentFunc";
        /// <summary>
        /// 根据文件路径生成类名称
        /// </summary>
        /// <param name="filePath"></param>
        /// <returns></returns>
        public static string GenerateClassNameByFilePath(string filePath)
        {
            string className = filePath.Replace(AppPath, "").Replace("\\", "_");
            int iIndex = className.LastIndexOf('.');
            className = className.Substring(0, iIndex);
            className = className.Replace(".", "");
            return className;
        }
        /// <summary>
        /// 是否是关键字
        /// </summary>
        /// <param name="str"></param>
        /// <returns></returns>
        public static bool IsKeyWord(string str)
        {
            if (string.IsNullOrEmpty(str))
            {
                return false;
            }
            str = str.Trim();
            if (str.Equals("{"))
            {
                return true;
            }
            if (str.Equals("}"))
            {
                return true;
            }
            if (str.Equals("else{"))
            {
                return true;
            }
            if (str.StartsWith("if(") && str.EndsWith("{"))
            {
                return true;
            }
            if (str.StartsWith("for(") && str.EndsWith("{"))
            {
                return true;
            }
            if (str.StartsWith("foreach(") && str.EndsWith("{"))
            {
                return true;
            }
            if (str.StartsWith("try{"))
            {
                return true;
            }
            if (str.StartsWith("catch(") && str.EndsWith("{"))
            {
                return true;
            }
            if (str.StartsWith("catch{"))
            {
                return true;
            }
            if (str.StartsWith("finally{"))
            {
                return true;
            }
            return false;
        }

    }
}
